//
//  JHHeader.h
//  JuniRengLish_iOS
//
//  Created by revogi on 2019/5/8.
//  Copyright © 2019 revogi. All rights reserved.
//

#ifndef JHHeader_h
#define JHHeader_h
// 快速设置颜色
#define JKColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]
#define JKColorAlpha(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)]

#define pageMenuH 40

// 全局灰色背景色
#define JKGlobalBgColor JKSameRGBColor(241)



#define JK99TextColor  JKColor(153, 153, 153)

#define JK66TextColor  JKColor(102, 102, 102)

#define JK33TextColor  JKColor(51, 51, 51)

//16进制颜色
#define JKGetColor(r) [GetColor16 hexStringToColor:r]

// 主色调
#define JKMainColor JKGetColor(@"00bba1")

// 随机色
#define JKRandomColor [UIColor colorWithRed:arc4random_uniform(100)/100.0 green:arc4random_uniform(100)/100.0 blue:arc4random_uniform(100)/100.0 alpha:1]

#define JKRandomColorAlpha(a) [UIColor colorWithRed:arc4random_uniform(100)/100.0 green:arc4random_uniform(100)/100.0 blue:arc4random_uniform(100)/100.0 alpha:(a)]

// RGB相等颜色
#define JKSameRGBColor(rgb) [UIColor colorWithRed:(rgb)/255.0 green:(rgb)/255.0 blue:(rgb)/255.0 alpha:1]
#define JKSameRGBColorAlpha(rgb, a) [UIColor colorWithRed:(rgb)/255.0 green:(rgb)/255.0 blue:(rgb)/255.0 alpha:(a)]


#define KPCOLOR(hex) [UIColor colorWithRed:((float)((hex & 0xFF0000) >> 16)) / 255.0 green:((float)((hex & 0xFF00) >> 8)) / 255.0 blue:((float)(hex & 0xFF)) / 255.0 alpha:1]





// 2.屏幕尺寸

/** 屏幕bounds */
#define JKScreenBounds [UIScreen mainScreen].bounds
/** 屏幕宽度 */
#define JKScreenW [UIScreen mainScreen].bounds.size.width
/** 屏幕高度 */
#define JKScreenH [UIScreen mainScreen].bounds.size.height


// 四英寸屏幕缩小
#define JKFourInchScale (([UIScreen mainScreen].bounds.size.width < 330) ? 0.853 : 1)


//存储对象
#define kUserDefaults  [NSUserDefaults standardUserDefaults]


//不管横竖屏都获取较短的那个长度
#define AUTO_SCREEN_WIDTH (([UIScreen mainScreen].bounds.size.width > [UIScreen mainScreen].bounds.size.height)?[UIScreen mainScreen].bounds.size.height:[UIScreen mainScreen].bounds.size.width)


//自适应尺寸(以6s尺寸为基准，例如参数中的value值为10 在6s上为10 在Plus上为value/375*Plus的屏幕宽度，此外这个尺寸只以屏幕宽度为准，就算横屏状态下横竖颠倒，依然以短的尺寸为宽度)
#define kWidthScale(value)  (((value)/375.0) * (([UIScreen mainScreen].bounds.size.width > [UIScreen mainScreen].bounds.size.height)?[UIScreen mainScreen].bounds.size.height:[UIScreen mainScreen].bounds.size.width))


//获取构建版本号
#define KBuild_Version [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]

// 3.常用对象
#define kApplication [UIApplication sharedApplication]
#define kAppDelegate ((AppDelegate *)[UIApplication sharedApplication].delegate)
#define kAppWindow  [UIApplication sharedApplication].keyWindow

#define kNotificationCenter [NSNotificationCenter defaultCenter]




#define kUserDefaults [NSUserDefaults standardUserDefaults]
#define kNotificationCenter [NSNotificationCenter defaultCenter]

// 4.获取常用
//APP版本号
#define kAppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
//系统版本号
#define kSystemVersion  [[UIDevice currentDevice] systemVersion]
//获取当前语言
#define kCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])
//判断是否为iPhone
#define kIsiPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
//判断是否为iPad
#define kIsiPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
//判断是否为横屏
#define kIsLandscape ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft || [UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight)
//获取沙盒Document路径
#define kDocumentPath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
//获取沙盒temp路径
#define kTempPath NSTemporaryDirectory()
//获取沙盒Cache路径
#define kCachePath [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]


//7.获取通知中心
#define kNotificationCenter  [NSNotificationCenter defaultCenter]

//weakSelf
#define XTWeakSelf __weak typeof(self) weakSelf = self;

//8.获取UIImage

#define GUIImageFor(imageName) [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]


//9. 适配iPhone X

// 第一个参数是当下的控制器适配iOS11 一下的，第二个参数表示scrollview或子类
#define  AdjustsScrollViewInsetNever(controller,view)   if(@available(iOS 11.0, *)) {view.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;} else if([controller isKindOfClass:[UIViewController class]]) {controller.automaticallyAdjustsScrollViewInsets = false;}

/// 高度系数 812.0 是iPhoneX的高度尺寸，667.0表示是iPhone 8 的高度，如果你觉的它会变化，那我也很无奈
#define kWJHeightCoefficient (kScreenHeight == 812.0 ? 667.0/667.0 : kScreenHeight/667.0)


#define iPad    [[UIDevice currentDevice].model isEqualToString:@"iPad"]
#define iPhone  [[UIDevice currentDevice].model isEqualToString:@"iPhone"]
#define iPod    [[UIDevice currentDevice].model isEqualToString:@"iPod touch"]

#define iPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960) , [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(1242,2208), [[UIScreen mainScreen] currentMode].size) || CGSizeEqualToSize(CGSizeMake(1125,2001), [[UIScreen mainScreen] currentMode].size)) : NO)
#define iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125,2436), [[UIScreen mainScreen] currentMode].size) : NO)

#define iPhoneXr  ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828,1792), [[UIScreen mainScreen] currentMode].size) : NO)

#define iPhoneXsMax  ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242,2688), [[UIScreen mainScreen] currentMode].size) : NO)

// status bar height.
#define  kStatusBarHeight      (IS_IPhoneX_All ? 44.f : 20.f)
// Navigation bar height.
#define  kNavigationBarHeight  44.f
// Tabbar height.
#define  kTabbarHeight        (IS_IPhoneX_All ? (49.f+34.f) : 49.f)
// Tabbar safe bottom margin.
#define  kTabbarSafeBottomMargin        (IS_IPhoneX_All ? 34.f : 0.f)
// Status bar & navigation bar height.
#define  kStatusBarAndNavigationBarHeight  (IS_IPhoneX_All ? 88.f : 64.f)

//机型判断
#define IS_iPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)

#define IS_iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)

#define IS_iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) || CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size)) : NO)

#define IS_iPhone6plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(1125, 2001), [[UIScreen mainScreen] currentMode].size) || CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size)) : NO)

#define IS_IPHONE6PLUS ((UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) && [[UIScreen mainScreen] nativeScale] == 3.0f)

//判断是否是ipad
#define isPad ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)

//判断是否iPhone X
#define IS_iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)

//判断iPHoneXr
#define IS_IPHONE_Xr ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) && !isPad : NO)
//判断iPhoneXs
#define IS_IPHONE_Xs ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !isPad : NO)
//判断iPhoneXs Max
#define IS_IPHONE_Xs_Max ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size) && !isPad : NO)

#define IS_IPhoneX_All (IS_IPHONE_Xs_Max == YES || IS_IPHONE_Xs == YES || IS_IPHONE_Xr == YES || IS_iPhoneX == YES)


#define JKStatusBarHeight ([UIApplication sharedApplication].statusBarFrame.size.height)
#define JKNavBarHeight ([UIApplication sharedApplication].statusBarFrame.size.height + 44)
#define JKTabBarHeight (self.tabBarController.tabBar.height)
#define JKBottomSafeAreaHeight (34)
#define JKIsIphoneX ([UIApplication sharedApplication].statusBarFrame.size.height >= 44)


#define kStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height
#define kNavBarHeight 44.0

//导航栏和状态栏的高度
#define kTabBarHeight ([[UIApplication sharedApplication] statusBarFrame].size.height>20?83:49)

//底部tabbar的高度
#define kTopHeight  (kStatusBarHeight + kNavBarHeight)

// 10.测试的时候打印语句，发布程序的时候自动去除打印语句
#ifdef DEBUG
#define MYLog(...) NSLog(@"%s 第%d行 \n %@\n\n",__func__,__LINE__,[NSString stringWithFormat:__VA_ARGS__])
#else
#define MYLog(...)
#endif

// 弱引用self
#define JKWeakSelf  __weak typeof(self) weakSelf = self;

#define WEAKSELF __weak __typeof(&*self)weakSelf = self;

#endif /* JHHeader_h */
